import { createApp } from 'vue'
import { createPinia } from 'pinia'
import L from "leaflet";
import 'leaflet/dist/leaflet.css'
import 'leaflet.pm';
import 'leaflet.pm/dist/leaflet.pm.css';
import App from './App.vue'
import router from './router'
import './assets/css/main.less'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
import axios from "axios";
import directives from './directive/index';
import "/node_modules/flag-icons/css/flag-icons.min.css";
// import "flag-icon-css/css/-icons.css";

// axios.interceptors.response.use((response) => {      
//   if (response.data.code != 200 && response.data != 200 && response.config.responseType != 'blob'&&response.data!='success'&&response.data.msg!='操作成功') {
//     return Promise.reject(response.data.message);
//   } else {
//     return response;
//   }
// }, (error) => {
  
//   let message = "";
//   if (error && error.response) {
//     switch (error.response.status) {
//       case 302:
//         message = "接口重定向了！";
//         break;
//       case 400:
//         message = "参数不正确！";
//         break;
//       case 401:
//         message = "您未登录，或者登录已经超时，请先登录！";
//         break;
//       case 403:
//         message = "您没有权限操作！";
//         break;
//       case 404:
//         message = `请求地址出错: ${error.response.config.url}`;
//         break;
//       case 408:
//         message = "请求超时！";
//         break;
//       case 409:
//         message = "系统已存在相同数据！";
//         break;
//       case 500:
//         message = "服务器内部错误！";
//         break;
//       case 501:
//         message = "服务未实现！";
//         break;
//       case 502:
//         message = "网关错误！";
//         break;
//       case 503:
//         message = "服务不可用！";
//         break;
//       case 504:
//         message = "服务暂时无法访问，请稍后再试！";
//         break;
//       case 505:
//         message = "HTTP 版本不受支持！";
//         break;
//       default:
//         message = "异常问题，请联系管理员！";
//         break;
//     }
//   }
//   return Promise.reject(message);
// });

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(Antd)
app.use(ElementPlus, { locale: zhLocale })

// app.directive('color', (el, binding) => {
//   el.style.color = binding.value
// })

directives(app)

app.mount('#app')


/**
 * 模拟C#的padleft
 * @param {any} totalWidth 字符总长度
 * @param {any} paddingChar 补全的字符
 */
String.prototype.PadLeft = function (totalWidth, paddingChar) {
    if (paddingChar !== null) {
        return this.PadHelper(totalWidth, paddingChar, false);
    } else {
        return this.PadHelper(totalWidth, ' ', false);
    }
}
String.prototype.PadRight = function (totalWidth, paddingChar) {
    if (paddingChar !== null) {
        return this.PadHelper(totalWidth, paddingChar, true);
    } else {
        return this.PadHelper(totalWidth, ' ', true);
    }
}
String.prototype.PadHelper = function (totalWidth, paddingChar, isRightPadded) {
    if (this.length < totalWidth) {
        let paddingString = new String();
        for (let i = 1; i <= (totalWidth - this.length); i++) {
            paddingString += paddingChar;
        }
        if (isRightPadded) {
            return (this + paddingString);
        } else {
            return (paddingString + this);
        }
    } else {
        return this;
    }
}
